import {
	defineStore
} from "pinia";
import {
	getUserInfo
} from '@/api/userinfo.js'

export const useUserinfo = defineStore('userinfo', {
	state: () => {
		return {
			imageUrl: '',
			name: '',
			sex: "",
			department: '',
			identity: '',
			account: '',
			email: ''
		}
	},
	actions: {
		async userinfo(id) {
			const res = await getUserInfo(id)
			this.imageUrl = res.image_url
			this.name = res.name
			this.sex = res.sex
			this.department = res.department
			this.identity = res.identity
			this.account = res.account
			this.email = res.email
		}
	},
}, {
	persist: {
		// 存储全部数据
		enabled: true,
		// 关键字
		key: 'userinfo',

		storage: localStorage
	}
})